# -*- coding: utf-8 -*-
# coding=utf-8
'''
@author: Administrator
'''
import os
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parentdir)


import DBCenter


'''
    从warehouse表导入数据到area
'''
            
def Run():
    select_warehouse_sql = '''
        SELECT * FROM `warehouse`
    '''
    warehouse_datas = DBCenter.rc_db.query(select_warehouse_sql)
    
    
    for warehouse_data in warehouse_datas:
        insert_area_sql = '''
            INSERT INTO `area`
                        (`area_name`,
                         `domain_name`,
                         `province_id`,
                         `province_name`,
                         `city_id`,
                         `city_name`,
                         `district_id`,
                         `district_name`,
                         `address`,
                         `contacter`,
                         `cellphone`,
                         `qq`,
                         `remark`,
                         `sort`,
                         `status`,
                         `create_user`,
                         `create_date`)
            VALUES ('%s',
                    '',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    %s,
                    %s,
                    'AreaImport',
                    NOW())
        ''' % (
                warehouse_data['warehouse_name'],
                warehouse_data['province_id'],
                warehouse_data['province_name'],
                warehouse_data['city_id'],
                warehouse_data['city_name'],
                warehouse_data['district_id'],
                warehouse_data['district_name'],
                warehouse_data['address'],
                warehouse_data['contacter'],
                warehouse_data['cellphone'],
                warehouse_data['qq'],
                warehouse_data['remark'],
                warehouse_data['sort'],
                warehouse_data['status']
               )
        DBCenter.rc_db.execute(insert_area_sql)
    
Run()
print 'succ'
# print os.getcwd()



